<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>获取验证码</div>
    <script>
        const div = document.querySelector("div");
        div.onclick = function () {
            div.style = 'pointer-events:none'
            let time = 3
            div.innerText = time + "秒后再获取"
            let timeid = setInterval(() => {
                time--
                div.innerText = time + "秒后再获取"
                if (time === -1) {
                    clearInterval(timeid)
                    div.style = 'pointer-events:auto'
                    div.innerText = "获取验证码"
                }
            }, 1000)
        }

    </script>
</body>

</html>